﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace nr.Tombola.Windows.Player
{
    public partial class CardViewForm : Form
    {
        public int[] Numbers { get; set; }
        public nr.Tombola.Cards.Card Card { get { return card.Card; } set { card.Card = value; Text = string.Format("Cartella <{0}>", value.Name); } }

        public CardViewForm()
        {
            InitializeComponent();
        }

        private void btnCheckWins_Click(object sender, EventArgs e)
        {
            card.Purge();
            foreach (int number in Numbers) card.TurnNumber(number, true);
            int maxWin = 0;
            int fullRows = 0;
            for (int row = 0; row < 3; ++row)
            {
                int rowTotal = 0;
                for (int dec = 0; dec < 9; ++dec)
                    if (Numbers.Contains(card.Card[row][dec])) ++rowTotal;
                if (rowTotal == 5) ++fullRows;
                if (maxWin < rowTotal) maxWin = rowTotal;
            }
            string[] messages = new string[] { "Nessun numero.", "Solo un numero.", "Ambo.", "Terno.", "Quaterna.", "Cinquina." };
            string message = messages[maxWin];
            if (fullRows == 3) message = "TOMBOLA!!!";
            MessageBox.Show(message, "[nr.Tombola] Controller di Gioco", MessageBoxButtons.OK);
        }
    }
}
